package com.molin.extensionTest.getClassNameModel;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Demo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        //1.获取class对象
        Class clazz = Class.forName("com.molin.extensionTest.getClassNameModel.Student");

        //2.获取构造方法对象
        Constructor constructor = clazz.getConstructor(String.class, int.class);

        //3.利用newInstance创建Student的对象
        Student zhangsan = (Student) constructor.newInstance("zhangsan", 23);
        System.out.println(zhangsan.toString());
        zhangsan.sayHi();

    }
}
